<template>
    <div class="wrapper">
        <!-- v-if="list.length"是因为一开始传的是一个空数组，轮播图会从第四张开始播放，这样可以解决 -->
        <swiper :options="swiperOption" v-if="showSwiper">
            <swiper-slide v-for='item in list' :key="item.id">
                <img class="swiper-img" :src="item.imgUrl">
            </swiper-slide>
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
    name:'HomeSwiper',
    props:{
        list:Array
    },
    data(){
        return{
            swiperOption:{
                pagination:'.swiper-pagination',
                loop:true,
            }
            
        }
    },
    computed:{
        showSwiper(){
            return this.list.length;
        }
    }
}
</script>

<style lang="less" scoped>
    //样式穿透（/deep/是sass和less的穿透，stylus是 >>> )
    .wrapper /deep/ .swiper-pagination-bullet-active{
        background: #fff;
    }
    .wrapper{
        overflow: hidden;
        width: 100%;
        height: 0;
        padding-bottom: 29%;//即高度为宽度的29%
        .swiper-img{
            width: 100%;
        }
    }
    
</style>

